{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "def diamond(width, height, h):\n",
    "        if h < height//2:\n",
    "            inset = int(((height//2-h) * (width//2))/(height//2))\n",
    "        else:\n",
    "            inset = int(((h-height//2) * (width//2))/(height//2))\n",
    "        row = (\n",
    "            [random.randint(0, int(i*256/inset)) for i in range(inset)]\n",
    "            + [0xff for j in range(width-2*inset)]\n",
    "            + [random.randint(0, int((inset-k)*256/inset)) for k in range(inset)]\n",
    "        )\n",
    "        return row"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "def ascii_art(width, height, scaled_b_w) -> None:\n",
    "    grayscale = \"$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcft/\\\\|()1{}[]?-_+~<>i!lI;:,\\\"^`'. \"\n",
    "    for r in range(height):\n",
    "        gray_char = lambda b: int(len(grayscale) * (b / 256))\n",
    "        gray = map(gray_char, scaled_b_w[r * width : (r + 1) * width])\n",
    "        text = \"\".join(grayscale[g] for g in gray)\n",
    "        print(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "$$B@a#dw8MBfcwW+`U*zQb@\\Q#**W$BB\n",
      "$@#*#aOBa8c*Z[%   dB/Y|ow0kk@o#B\n",
      "$@#%$qwqU@z*B;    zw*>?)#k*#ph@8\n",
      "$$WbBBB%df?U!      ,dlpYqBJh&@M@\n",
      "$$@pdJqd#*):        `(wbm\\0&Zh*%\n",
      "$%obW@qoqwq          <@d|bf0wbo&\n",
      "$W$@QLXh~h            ,@pW#Qm#hB\n",
      "$&oBp*)MQ              8U8ZWUBb$\n",
      "$8B@0Ja+                .]BahW$$\n",
      "$&hm||>                  /W}$aa&\n",
      "$omQ$%                    m0#$B$\n",
      "$Ww/h                       XW@#\n",
      "$&qh                        _h#M\n",
      "$dO                          zCm\n",
      "$f                            _0\n",
      "$                              `\n",
      "                                \n",
      "$                              '\n",
      "$O                            t#\n",
      "$%|                          lJ&\n",
      "$*hB                        '+@a\n",
      "$M@hk                      0oUwW\n",
      "$8Ma|>                    ca#qO&\n",
      "$&opb{Z                  }(aBO&B\n",
      "$%$oM$\\l                -X|(Z%oB\n",
      "$W&%dBdQi              ;[]&XL%k$\n",
      "$WBooUJWC{            qh(Y%#m$#&\n",
      "$$o*Bd$W|MW          1L_|dB@$8M8\n",
      "$$Ma$MUdo\\Jw        ;lX_}aWChb$&\n",
      "$@%hpwYkk*@f>      U)8Chat%OmkB@\n",
      "$B88%Bmh/ZB-*|    UtaqtCm&WqkBBB\n",
      "$@&#@oMo$qa#*/C  *IQmQ0f&LBMbo@$\n"
     ]
    }
   ],
   "source": [
    "width = height = 32\n",
    "\n",
    "image = bytes(\n",
    "        b\n",
    "        for h in range(height)\n",
    "        for b in diamond(width, height, h)\n",
    "    )\n",
    "\n",
    "ascii_art(width, height, image)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
